package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceDishMeal;
import com.zjjk.transfer.source.mapper.SourceDishMealMapper;
import com.zjjk.transfer.source.service.SourceDishMealService;
import com.zjjk.transfer.source.param.SourceDishMealPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 餐品分类 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceDishMealServiceImpl extends BaseServiceImpl<SourceDishMealMapper, SourceDishMeal> implements SourceDishMealService {

    @Autowired
    private SourceDishMealMapper sourceDishMealMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceDishMeal(SourceDishMeal sourceDishMeal) throws Exception {
        return super.save(sourceDishMeal);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceDishMeal(SourceDishMeal sourceDishMeal) throws Exception {
        return super.updateById(sourceDishMeal);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceDishMeal(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceDishMeal> getSourceDishMealPageList(SourceDishMealPageParam sourceDishMealPageParam) throws Exception {
        Page<SourceDishMeal> page = new PageInfo<>(sourceDishMealPageParam, OrderItem.desc(getLambdaColumn(SourceDishMeal::getCreateTime)));
        LambdaQueryWrapper<SourceDishMeal> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceDishMeal> iPage = sourceDishMealMapper.selectPage(page, wrapper);
        return new Paging<SourceDishMeal>(iPage);
    }

}
